#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

from analyze.analyzer import Analyzer
from ConfigParser import ConfigParser

def initialize(argv):
    from django.conf import settings
    from optparse import OptionParser
    import logging

    logging.basicConfig(format='%(asctime)s - %(levelname)-5s - %(name)-15s - %(message)s', level=logging.INFO, datefmt='%I:%M:%S')

    settings.configure(DEFAULT_CHARSET="utf-8")
    parser = OptionParser()
    parser.add_option("-c", "--config", dest="config", help="read config from FILE", metavar="FILE")

    (options, args) = parser.parse_args()
    if options.config is None:
        parser.print_help()
        return None
    cp = ConfigParser()
    cp.read(options.config)

    return cp

if __name__ == "__main__":
    config = initialize(sys.argv)

    if config is not None:
        level = config.getint("Common", "level")

        analyzer = Analyzer(level)

        analyzer.analyze(config=config)
        exit(0)
    else:
        exit(1)